<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Classes - Fuel Documentation</title>
	<link href="../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../assets/js/nav.js"></script>
	<script type="text/javascript" src="../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('general', '../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>FUEL Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2>Extending Core Classes</h2>

		<p><strong>Be sure to know what you are doing, extended core methods under the same name will be used by the
		core as well as by your application and this may result in unexpected behavior.</strong></p>

		<h3>Extending but not replacing the core class</h3>

		<p>These are the easiest and will work like any other class your create, just make them extend the core class
		in the global namespace:</p>

		<pre><code>class MyConfig extends Config {}</code></pre>

		<h3>Extending &amp; replacing core classes</h3>

		<p>If you want your core extension to be used by the core as well as by your own application you need to extend
		it under the same name but take it from the "Fuel\Core" namespace. Below is an example for the Config class
		which you create in "fuel/app/classes/config.php":</p>

		<pre><code>class Config extends Fuel\Core\Config {}</code></pre>

		<p>But classes that have the same name as core classes are ignored by default. To make the Autoloader recognize
		your replacement you need to register it in the application bootstrap file. Search for the lines below:</p>

		<pre><code>Fuel\Core\Autoloader::add_classes(array(
	// Add classes you want to override here
	// Example: 'View' => APPPATH.'classes/view.php',
));</code></pre>

		<p>As is explained in the comments you need to add the new Config class as follows:</p>

		<pre><code>Fuel\Core\Autoloader::add_classes(array(
	// Add classes you want to override here
	// Example: 'View' => APPPATH.'classes/view.php',
	'Config' => APPPATH.'classes/config.php',
));</code></pre>

		<p>After this the core class will have been replaced by your extension.<br />
		Note: the core class will still be available when used with full namespace prefixed. With the above example of
		extending "Config" you can still use the original by calling "Fuel\Core\Config".</p>

	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel PHP</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>
